﻿using MediatR;
using System.Threading.Tasks;
using System.Threading;
using EWC.Core.DependencyInjection;
using EWC.HIS.Domain.ViewManage.Do;
using EWC.Core.Application.Dtos;
using EWC.HIS.Application.Contracts.ViewService.Queries;
using EWC.HIS.Domain.ViewManage.Repositories;

namespace EWC.HIS.Application.ViewService.Handlers
{
    public class GetDepartmentsQueryHandler : IRequestHandler<GetDepartmentsQuery, PagedResultDto<DepartmentDo>>, IScopedDependency
    {
        private readonly IViewRepository _viewRepository;

        public GetDepartmentsQueryHandler(IViewRepository viewRepository)
        {
            _viewRepository = viewRepository;
        }

        public async Task<PagedResultDto<DepartmentDo>> Handle(GetDepartmentsQuery request, CancellationToken cancellationToken)
        {
            var registrations = await _viewRepository.GetPagedDepartments("", "", request.PagingOptions.PageIndex, request.PagingOptions.PageSize);
            return registrations;
        }
    }
}
